package other;

import java.util.Scanner;

public class JuZheng {
    public static void main(String[] args) {
        System.out.println("请输入您要打印的矩阵高度");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] nums = new int[n][n];
        int t = 1; //代表要填入的数字
        int x = 0;  //代表行
        int y = 0; //代表列

        nums[x][y] = t;
        while (x < n * n) {
            while (x < n - 1) {
                ++x;
                nums[x][y] = ++t;

            }
            while (y < n - 1) {
                ++y;
                nums[x][y] = ++t;

            }
            while (y - x < n - 1) {
                --x;
                nums[x][y] = ++t;

            }
            while (y >= nums.length - 1) {
                --y;
                nums[x][y] = ++t;
            }
        }


        //打印
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                System.out.print(nums[i][j] + " ");
            }
            System.out.println();
        }
    }
}









